$(document).ready(function(){
	var validator = $("#frmTradesmanAdd").validate({
		errorElement:'div',
		rules: {
			email: {
				required: true,
				email: true,
				remote: SITEROOT+"/modules/register/checkemailexits.php"
			},
			mobno: {
				required: true,
				minlength:10,/*,
				phoneAus: true*/
			},
			companyname: {
				required: true,
				remote: SITEROOT+"/modules/register/checkcompanynameexits.php"
			},
			firstname: {
				required: true,
				character:true,
				maxlength: 50				
			},
			lastname: {
				required: true,
				character:true,
				maxlength: 50				
			},
			postcode:{
				required: true,
				minlength:3
				//remote: SITEROOT+"/modules/register/checkpostalexits.php"
			},
			day:{
				required : true
			},
			month:{
				required : true
			},
			year:{
				required : true
			},
			gender:{
				required : true
			},
			password: {
				required: true,
				minlength:6,
				maxlength:20				
			},
			confpassword: {
				required: true,
				equalTo:"#password"				
			},			
			agree: {
				required: true
			},
			"catname[]":{
				required: true
			},
			"jobtype[]":{
				required: true
			},
			cardfirstname: {
				required: function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						},
				character:true,
				minlength:3,
				maxlength: 50				
			},
			cardllastname: {
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						},
				character:true,
				minlength:3,
				maxlength: 50				
			},
			billingaddr:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						},
				minlength:10
			},
			cardtype:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						}
			},
			state:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						}
			},
			city:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						}
			},
			cardpostalcode:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						},
				minlength:3
			},
			cardnumber:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						},
				number:true
			},
			cardcode:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						},
				number:true
			},
			cardmonth:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						}
			},
			carddate:{
				required:  function() {
							var chk_paymentdiv_value = $('#paymentdiv_value').val();
							if(chk_paymentdiv_value == '1')
								return true;
							else
								return false;
						}
			},
			"state_id[]":{
				required: true
			}/*,
			googlesearch:{
				required: true
			}	*/		
		},
		messages: {
			email: {
				required: "Enter email address",
				email: "Enter valid email address",
				remote: jQuery.format("Email Address Already In Use")
			},
			mobno: {
				required: "Enter phone number",
				minlength: "Please enter minimum 10 digits"
			},
			companyname: {
				required: "Enter company name",
				remote: jQuery.format("Company name already in use")
			},
			firstname: {
				required: "Enter your first name",
				character: "Please enter characters only",
				maxlength: "Name length should be maximum 50 characters"
			},
			lastname: {
				required: "Enter your last name",
				character: "Please enter characters only",
				maxlength: "Name length should be maximum 50 characters"
			},		
			postcode:{
				required: "Enter Postal code",
				minlength: "Please Enter Minimum 3 digits"
				//remote: jQuery.format("Enter only australian postal code")
			},
			day:{
				required : "Select day"
			},
			month:{
				required : "Select month"
			},
			year:{
				required : "Select year"
			},	
			gender:{
				required : "Select gender"
			},
			password: {
				required: "Enter password",
				maxlength: "Please Enter Maximum 20 Charaters ",
				minlength: "Please Enter Minimum 6 Charaters"
			},
			confpassword: {
				required: "Enter confirm password",	
				equalTo: "Please Re-Enter Password, passwords do not match"			
			},			
			agree: {
				required: "Please select terms and conditions."
			},
			"catname[]":{
				required: "Select Trade Category"	
			},
			"jobtype[]":{
				required: "Select Job Type"
			},
			cardfirstname:{
				required: "Enter your first name",
				character: "Please enter characters only",
				minlength: "Please Enter Minimum 3 Charaters",
				maxlength: "Name length should be maximum 50 characters"				
			},
			cardllastname: {
				required: "Enter your last name",
				character: "Please enter characters only",
				minlength: "Please Enter Minimum 3 Charaters",
				maxlength: "Name length should be maximum 50 characters"
			},
			billingaddr:{
				required: "Enter your billing address",
				minlength: "Please Enter Minimum 10 Charaters"
			},
			cardtype:{
				required: "Select Card Type"
			},
			state:{
				required: "Select State"
			},
			city:{
				required: "Select City"
			},
			cardpostalcode:{
				required: "Enter Postal Code",
				minlength: "Please Enter Minimum 3 Characters"
			},
			cardnumber:{
				required: "Enter Card Number",
				number: 	"Please enter digits only"	
			},
			cardcode:{
				required: "Enter Security Code",
				number: 	"Please enter digits only"	
			},
			cardmonth:{
				required: "Select Month"
			},
			carddate:{
				required: "Select Year"
			},
			"state_id[]":{
				required: "Please Select State"
			}/*,
			googlesearch:{
				required: "Please enter your postal code"
			}	*/	
		}
	});
	//jQuery.validator.addMethod("phoneAus",function(a,b){return this.optional(b)||a.length>14&&a.match(/^[0-9]{10}$|^\(0[1-9]{1}\)[0-9]{8}$|^[0-9]{8}$|^[0-9]{4}[ ][0-9]{3}[ ][0-9]{3}$|^\(0[1-9]{1}\)[ ][0-9]{4}[ ][0-9]{4}$|^[0-9]{4}[ ][0-9]{4}$/)},"Please specify a valid mobile number");

	
});


function addFixedRateRow()
{ 
	
	
	var AllOptions = "";
	$('#catname_0').find('option').each(function() {
	AllOptions = AllOptions + "<option value=\""+$(this).val()+"\" >"+$(this).text()+"</option>";
	});
	
	var ni = document.getElementById('feeratetable1');
	var numi = document.getElementById('feeratedivValue');
	var num = (document.getElementById("feeratedivValue").value -1)+ 2;
	numi.value = num;
		var divId = "feetr_"+num;
		var newdiv = document.createElement('div');  
		newdiv.setAttribute("id",divId);
		newdiv.innerHTML = "";
	

	
	newdiv.innerHTML = "<dl class='minht70'><select name='catname[]' id='catname_"+num+"' class='input3' onchange='showJobType();'>"+AllOptions+"</select><section class='clear'></section></dl> <section class='clear'></section>";
	
ni.appendChild(newdiv);
		
		document.getElementById('feerateDiv').value = num;
		document.getElementById("feeratedivValue").value = num;
		//document.getElementById('feerateDiv1').value = num1;	
}

function removeFixedRateRow()
{
	var d = document.getElementById('feeratetable1');
	var olddiv = document.getElementById('feetr_'+document.getElementById('feerateDiv').value);
	d.removeChild(olddiv);
	var num = document.getElementById('feerateDiv').value-1;
	document.getElementById('feerateDiv').value = num;
	document.getElementById('feeratedivValue').value = num;
	
	//showJobType();

	//var num1 = document.getElementById('feerateDiv1').value-1;
	//document.getElementById('feerateDiv1').value = num1;
}